<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Object</title>
</head>
<body>

</body>
<script>
    let x = {
        name:'x',
        age:'16',
        height:'170',
        weight:'70',
        score:{
            chinese:90,
            english:80,
            math:100
        },
        'jack':'joke',
        'x.y':'x.y'
    }
    // 访问对象属性
    x.name;        // 访问name属性
    x['jack'];    //  访问jack属性

    // js 动态类型  自由删除增加属性

    x.school = 'xiao';   // 增加属性
    x.leg = 2;
    delete x.height;    //  删除属性
    delete x.name;

    //  检查是否拥有某项属性

    'name' in x;   // 返回false
    'school' in x;  //  返回true

    //  条件判断

    let n = 20;
    if (n > 18){
        console.log('adult');}
    else{
        console.log('age<18');
        console.log('teenager');}

    // 测试BMI
    let xiao = {
        height :1.7,
        weight :80.5
    };
    let BMI = xiao.weight/(xiao.height*xiao.height);
    if (BMI < 18.5)
    {
        console.log('too low');
        console.log("需要加餐")
    }else if(18.5<=BMI<25)
    {
        console.log('normal')
    }
    else if(25<=BMI<30)
    {
        console.log('too high')
    }else if(BMI>=30){
        console.log('too high')
    }else{
        console.log('dangerous')
    }

    // 循环   for
    let x = 0;
    let i;
    for(i=1;i<=10000;i++){
        x= x+i;
    }

    let o = {
        name:'xiao',
        age:16,
        height:170,
        weight:70,
        score: {
            chinese: 90,
            english: 80,
            math: 100
        }
    };
    for(let key in o){
        console.log(key);
    }

    //   do ... while
    let a = 0;
    let f =99;
    while( f>0){
        a = a+f;
        f = f-2;
    }

    //  遍历数组

    let arr = ['bart','lisa','adam'];
    for (let i=0;i<arr.length;i++){
        console.log(arr[i]);
    }
    for (let i in arr){
        console.log(arr[i]);
    }

    //   map  set

    console.log('你的浏览器支持' );

    let names = ['xiao','lili','lala'];
    let m = new Map(['mike',66],['xiao',16],['lili',18]);
    m.get('mike')
</script>
</html>